package com.yhd.controller;

import com.yhd.entity.result.ResultVo;
import com.yhd.entity.wx.WxPayResult;
import com.yhd.service.CourseService;
import com.yhd.service.impl.WxPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@Api(value = "小程序活动相关")
@Slf4j
@RequestMapping(value = "/app/wx")
@CrossOrigin
public class AppWxPayController extends WebBaseController{
	@Autowired
	private CourseService courseService;
	@Autowired
	private WxPayService wxPayService;
	
	@ApiOperation(value = "微信支付", httpMethod = "GET",notes = "")
	//@ApiImplicitParams({@ApiImplicitParam(name = "orderNo", value = "订单号", required = true, paramType = "字符串")})
	@GetMapping("/pay")
	@ResponseBody
	public ResultVo<WxPayResult> wxPay(@RequestParam String orderNo) throws Exception {
		if (getUserInfo(request) == null) {
			return ResultVo.failure("10001","无访问权限，请先登录！");
		}
		return courseService.wxPay(orderNo, getUserInfo(request));
	}
	
	@ApiOperation(value = "微信支付回调接口", notes = "微信支付回调接口")
	@PostMapping(value = "/wxPayNotify")
	@ResponseBody
	public ResultVo wxPayNotify(HttpServletRequest request) throws Exception {
		wxPayService.wxPayNotify(request);
		return ResultVo.success();
	}
	
}
